import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:xiongmao_clean_flutter_module/res/colors.dart';

class AppRoveUserItemView extends StatefulWidget {
  @override
  _AppRoveUserItemViewState createState() => _AppRoveUserItemViewState();
}

class _AppRoveUserItemViewState extends State<AppRoveUserItemView> {
  List<String> items = ['Item 1', 'Item 2', 'Item 3'];

  VoidCallback? addListener;

  @override
  void initState() {
    super.initState();

    addListener ??= BoostChannel.instance.addEventListener("SelectPersonnel", (key, arguments) async {
      setState(() {
        items.add("1111");
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ListView.builder(
          padding: EdgeInsets.all(0),
          physics: NeverScrollableScrollPhysics(),
          // 禁止滑动
          shrinkWrap: true,
          itemCount: items.length,
          itemBuilder: (context, index) {
            return ListTile(
              title: Text(items[index]),
              trailing: IconButton(
                icon: Image.asset(
                  'assets/images/base/icon_base_del.png',
                  width: 26,
                  height: 26,
                ),
                onPressed: () {
                  setState(() {
                    items.removeAt(index);
                  });
                },
              ),
            );
          },
        ),
        Container(
          child: InkWell(
            onTap: () {
              BoostChannel.instance.sendEventToNative("native_CommonEvent", {"method": "select_personnel_native"});
            },
            child: const Text(
              "+添加",
              textAlign: TextAlign.center,
              style: TextStyle(color: Colours.base_primary_blue),
            ),
          ),
        ),
      ],
    );
  }
}
